<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>后台管理系统</title>
    <include file="public/header"/>
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css">
    <link rel="stylesheet" href="/static/admin/style/admin.css">

</head>
<body  class="layui-layout-body">
<div id="LAY_app">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-body" id="LAY_app_body">
            <!-- 内容主体区域 -->
            <!--            <div style="padding: 15px;">内容主体区域。记得修改 layui.css 和 js 的路径</div>-->
            <div class="layadmin-tabsbody-item layui-show">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="username" lay-verify="required" lay-reqtext="账号是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">验证手机</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input demo-phone">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">验证码</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input type="text" name="vercode" lay-verify="required" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                        <div class="layui-form-mid" style="padding: 0!important;">-->
<!--                            <button type="button" class="layui-btn layui-btn-primary" lay-on="get-vercode">获取验证码</button>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">请务必填写密码</div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                            <button class="layui-btn" lay-submit="" lay-filter="demo2">跳转式提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- 辅助元素，一般用于移动设备下遮罩 -->
        <div class="layadmin-body-shade" layadmin-event="shade"></div>
        <div class="layui-footer">
            <!-- 底部固定区域 -->
        </div>
    </div>
</div>

<script src="/static/layui/layui.js"></script>
<script>
    //JS
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');

    layui.use(['form','element', 'layer', 'util'], function(){
        var element = layui.element
            ,layer = layui.layer
            ,form = layui.form
            ,util = layui.util
            ,$ = layui.$;
        //自定义验证规则
        form.verify({
            username: function(value){
                if(value.length < 3){
                    return '用户名大于3个字符';
                }
            }
            ,password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });

        //提交事件
        form.on('submit(demo1)', function(data){
            $.ajax({
                url:'login',
                data:data.field,
                method:'POST',
                success:function(res){
                    console.log('success',res)
                    if(res.code==1){
                        window.location.href="/admin/index/index"
                    }else{
                        layer.msg(res.msg)
                    }
                },
                error:function(res){
                    console.log('error',res)
                },
                complete:function(res){
                    console.log('complete',res)
                }
            })
            return false;
        });



    });
</script>
</body>
</html>